package com.yikaiye.android.yikaiye.ui.activity.order.viewmodel;

import androidx.lifecycle.MutableLiveData;

import com.google.gson.Gson;
import com.yikaiye.android.yikaiye.base.BaseViewModel;
import com.yikaiye.android.yikaiye.config.Constant;
import com.yikaiye.android.yikaiye.di.retrofit.BaseModel;
import com.yikaiye.android.yikaiye.di.retrofit.BaseNetCallback;
import com.yikaiye.android.yikaiye.model.CompanyRecordsModel;

import java.util.HashMap;
import java.util.Map;

public class MyCompanyViewModel extends BaseViewModel {

    public MutableLiveData<CompanyRecordsModel> companyRecordsModelMutableLiveData = new MutableLiveData<>();

    /**
     * 查找我的企业
     */
    public void getMyCompanyList(int page, String keyword) {
        Map<String, Object> map = new HashMap<>();
        map.put("pageNum", page);
        map.put("pageSize", Constant.PAGE_SIZE);
        map.put("keyword", keyword);
        addSubscribe(mRetrofitHelper.getMyCompanyList(new Gson().toJson(map)).subscribeWith(new BaseNetCallback<CompanyRecordsModel>() {

            @Override
            public void onSuccess(BaseModel<CompanyRecordsModel> baseModel) {
                if (Constant.SUCCESS == baseModel.getCode() && baseModel.getData() != null) {
                    companyRecordsModelMutableLiveData.setValue(baseModel.getData());
                } else {
                    mErrorData.setValue(baseModel.getMsg());
                }
            }

            @Override
            public void onError(String message) {
                super.onError(message);
                mErrorData.setValue(message);
            }
        }));
    }
}
